#include <stdio.h>
#include <stdbool.h>

int lengthOfLastWord(char* s) {
    int len = strlen(s);
    int count = 0;
    bool findNotSpace = false;

    while (len-- > 0) {
        if(s[len] == ' ' && !findNotSpace)
            continue;
        else
            findNotSpace = true;
        if(s[len] != ' ') {
            count++;
        }
        else
            break;
    }
    return count;
}

int main() {
    printf("The last word's length is %d\n", lengthOfLastWord("   fly me   to   the moon  "));
    return 0;
}